<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2018/8/27
  Time: 13:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<html>
<head>
    <title>定位地址参照</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/dataTables.bootstrap.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${assets}/css/views/department/departmentMgr.css">
    <script src="${newframe}/js/compatible.js"></script>
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <style>
        #example_paginate{
            text-align: center;
        }
    </style>
</head>
<body>
<div>
    <%@ include file="../../breadline.jsp" %>
</div>
<div id="serviceLocation" class="wrap">
    <%--<div class="page-header">--%>
        <%--<!-- /.page-header -->--%>
        <%--<ul class="page_nav">--%>
            <%--<li class="first cur">--%>
                <%--<a href="#" onClick="window.parent.showSrc('${URL_LAYOUT}')" class="cur">首页</a>--%>
                <%--<span>&nbsp;&nbsp;&nbsp;&nbsp;&gt;&nbsp;&nbsp;&nbsp;&nbsp;</span>--%>
            <%--</li>--%>
            <%--<li>--%>
                <%--基础设置--%>
                <%--<span>&nbsp;&nbsp;&nbsp;&nbsp;&gt;&nbsp;&nbsp;&nbsp;&nbsp;</span>--%>
            <%--</li>--%>
            <%--<li>定位地址参照</li>--%>
        <%--</ul>--%>
    <%--</div>--%>
    <div class="content">
        <h1>定位地址参照</h1>
        <div class="form">
            <label for="locationAddress" style="width:55px;">定位:</label>
            <input id="locationAddress" type="text" class="SN" placeholder="输入定位地址">
            <label for="inspectionName" style="width:55px;">检验所:</label>
            <input type="text" id="inspectionName" class="SN" placeholder="输入检验所名字">
            <label for="serverAddress" style="width:55px;">服务器:</label>
            <input type="text" id="serverAddress" class="SN" placeholder="输入服务器地址">
            <label for="partitionNumber" style="width:55px;">分区号:</label>
            <input type="text" id="partitionNumber" class="SN" placeholder="输入分区号">
            <button class="search" id="query" onclick="refreshTable();">搜索</button>
        </div>
        <div id="tablepart">
            <table id="example" class="display" cellspacing="10" width="100%">
                <thead>
                <tr style="background:#e6e6e6;">
                    <th>
                        <%--<input id="all_id" type="checkbox"><label style="margin-left:10px;" for="all_id" class="checkboxLabelClass" onclick="isCheckedAll()"></label>--%>
                    </th>
                    <th>id</th>
                    <th>定位地址</th>
                    <th>首字母</th>
                    <th>检验所名字</th>
                    <th>服务器地址</th>
                    <th>分区号</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
    <div class="loading" style="display: none;">
        <img src="${newframe }/images/slidebar/loading.gif" class="loadingImg">
    </div>
</div>
<script>
    //判断是否已经全选
    function isCheckedAll(){
        $("#all_id").click(function(){

            if($(this).is(":checked")){
                console.log('yes');
                $(this).toggleClass('checkBoxSelected');
                $(".CheckBoxLabelClass").removeClass();
                $("label[for='id']").addClass("CheckBoxSelected");
            }

        });
    }
    function toAdd(){
        window.parent.showNewModelIframe("${URL_SERVICE_TOSAVE}?method=1",850,400);
    }
    function toUpdate(){
        var checkedArray = getCheckedArray();
        if (checkedArray.length != 1) {
            alert("请勾选一条数据修改");
            return;
        }
        window.parent.showNewModelIframe("${URL_SERVICE_TOUPDATE}?id="
            + checkedArray[0] + "&method=2", 850, 400);
    }
    function toDelete(){
        var checkedArray = getCheckedArray();
        var ids = "";
        if (checkedArray.length == 0) {
            alert("请勾选至少一项数据");
            return;
        } else {
            for (var i = 0; i < checkedArray.length; i++) {
                ids += checkedArray[i] + ",";
            }
            ids = ids.substring(0, ids.length - 1);
        }
        var r = confirm("确定要删除勾选的数据吗?");
        if (r == true) {
            $.ajax({
                url : '${URL_SERVICE_DELETE}',//删除地址
                dataType : 'json',
                type : 'post',
                data : {
                    ids : ids
                },
                async : false, //默认为true 异步
                error : function() {
                    alert('error');
                },
                success : function(data) {

                    if (!data.success) {
                        alert("刪除失敗，失敗原因：" + data.msg);
                    }
                    refreshTable();
                }
            });
        }
    }
    var table;
    function initTable() {
        table = $('#example')
            .DataTable({
                "dom" : "<'row'<'#mytool.col-xs-10'><'col-xs-6'f>r>"
                    + "t"
                    + "<'row pageNum'<p>>",
                "bFilter" : false,//去掉搜索框
                "sLengthMenu":[10],
                "bAutoWidth" : true, //自适应宽度
                "bInfo":false,
                "sPaginationType" : "full_numbers",
                "ordering" : false,//是否允许Datatables开启排序
                "bProcessing" : true,
                "bServerSide" : true,
                "sScrollX":"100%",
                "sAjaxSource" : "${URL_SERVICE_SEARCHSERVICELOCATION}",
                "sAjaxDataProp" : "dataList",//查询后，返回的集合
                "fnServerData" : function(sSource, aoData, fnCallback) { //查询条件
                    aoData.push(
                        {"name": "locationName", "value": $("#locationAddress").val()},
                        {"name": "checkName", "value": $("#inspectionName").val()},
                        {"name": "serviceUrl", "value": $("#serverAddress").val()},
                        {"name": "partition", "value": $("#partitionNumber").val()}
                    );
                    $.ajax({
                        "dataType" : 'json',
                        "url" : sSource,
                        "type" : 'post',
                        "data" : aoData,
                        "success" : function(resp){
                            // var page = parseInt(resp.data.iTotalDisplayRecords / 10) ;
                            // if(page >= 9){
                            //     page = 9;
                            //     var W = page * 45;
                            // }else if(page ==0){
                            //     var W = 360;
                            // }else{
                            //     var W = page*60;
                            // }
                            // $('.pageNum').width(W + 'px');
                            console.log(resp);
                            fnCallback(resp);
                        }
                    });
                },
                "aoColumns" : [
                    {
                        "targets" : 0,
                        "data" : null,
                        "fnCreatedCell" : function(nTd, sData, oData, iRow, iCol) {
                            $(nTd).html('' + '&nbsp;&nbsp;<input name="id" id = "'+oData.id + '" class="checkboxClass" value="' + oData.id + '" type="checkbox"><label for='+oData.id+' class="checkboxLabelClass"></label>' + '');
                        }
                    },
                    {
                        "mDataProp" : "id"
                    },
                    {
                        "mDataProp" : "locationName"
                    },
                    {
                        "mDataProp" : "firstLetter"
                    },
                    {
                        "mDataProp" : "checkName"
                    },
                    {
                        "mDataProp" : "serviceUrl"
                    },
                    {
                        "mDataProp" : "partition"
                    }
                ],
                "aoColumnDefs": [{ "bVisible": false, "aTargets": [1]}],//隐藏列
                "oLanguage" : {//插件的汉化
                    "sLengthMenu" : '',
                    "sInfoEmpty" : "没有数据",
                    "sInfoFiltered" : "(从 _MAX_ 条数据中检索)",
                    "oPaginate" : {
                        "sFirst" : "",
                        "sPrevious" : "<b>上一页<b>",
                        "sLast" : "",
                        "sNext" : "<i>下一页</i>"

                    },
                    "sZeroRecords" : "没有检索到数据",
                    "sProcessing" : "<img src='' />",
                    "sSearch" : "搜索"
                },
                "initComplete" : function() {
                    $("#mytool").append('<button id="delete_butt" type="button" onclick="toDelete()" >删除</button>');
                    $("#mytool").append('<button id="update_butt" type="button" onclick="toUpdate()" >修改</button>');
                    $("#mytool").append('<button id="add_butt" type="button" onclick="toAdd()" >添加</button>');
                }
            });
    }
    function getCheckedArray() {
        var checkedArray = [];
        $("input[name='id']").each(function() {
            if (this.checked) {
                checkedArray.push(this.value);
            }
        });
        return checkedArray;
    }
    $(document).ready(function() {
        initTable();
    });
</script>
</body>
</html>
